import 'package:async/async.dart';
import 'package:boss/models/package_group.dart';
import 'package:boss/provider/package_group_provider.dart';
import 'package:boss/ui/widget/center_title_app_bar.dart';
import 'package:boss/ui/widget/loader/loader.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';
import 'package:provider/provider.dart';
import 'package:router/annotation.dart';

import 'widget/package_group_browser.dart';

@RouterConfig(PackageGroupPage.pageName)
class PackageGroupPage extends StatefulWidget {
  static const pageName = '/packageGroup';

  const PackageGroupPage({
    Key key,
  }) : super(key: key);

  @override
  _PackageGroupPageState createState() => _PackageGroupPageState('套餐分组');
}

class _PackageGroupPageState extends BaseState<PackageGroupPage> {
  _PackageGroupPageState(String pageName) : super(pageName);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CenterTitleAppBar(title: '套餐分组'),
      body: Loader<List<PackageGroup>>(
        loadTask: _loadTask,
        builder: (context) {
          return PackageGroupBrowser();
        },
      ),
    );
  }

  Future<Result<List<PackageGroup>>> _loadTask() {
    var packageGroupProvider = Provider.of<PackageGroupProvider>(
      context,
      listen: false,
    );
    return packageGroupProvider.initData();
  }
}
